# -*- coding: utf-8 -*-

from django.db import models
from core.models import CoreModel, table_prefix
import reversion


"""接口对象"""


@reversion.register()
class Interface(CoreModel):
    product = models.ForeignKey(
        to='pms.Product',
        related_name="interface_set",
        on_delete=models.CASCADE,
        db_constraint=False,
        verbose_name="所属产品"
    )
    name = models.CharField(
        max_length=128,
        verbose_name="接口名称"
    )
    type = models.CharField(
        max_length=50,
        default='0',
        verbose_name="接口类型"
    )
    url = models.CharField(
        max_length=256,
        verbose_name="接口地址"
    )

    def __str__(self) -> str:
        return self.name

    class Meta:
        unique_together = (('product', 'url'),)
        db_table = table_prefix + "rms_interface"
        verbose_name = '接口对象'
        verbose_name_plural = verbose_name
        ordering = ('-update_time',)
